

import csv
import numpy as np
import os



x,y = [], []


keyword = 'AX'
color= 'Cy5'
dir='distribution/'+color+'/'
sizefactor=20

for fname in os.listdir(dir):

    if keyword in fname:
        csv_file = open(dir+fname)

        # Read off and discard first line, to skip headers
        csv_file.readline()
        fx,fy = [], []
        

        # Split columns while reading
        for Volume,Surface,NbObjVoxels,NbSurfVoxels,IntDen,Mean,StdDev,Median,Min,Max,X,Y,Z,MeanDist,SDDist,MedianDist,XM,YM,ZM,BX,BY,BZ,Bwidth,Bheight,Bdepth in csv.reader(csv_file, delimiter=','):
            # Append each variable to a separate list
            cnt=int(int(Volume)/sizefactor)
            
            if cnt == 0:
                cnt=1

            for _ in range(cnt):
                fx.append(float(X))
                fy.append(float(Y))            

        
              
        fx = [a - min(fx) for a in fx]
        fy = [a - min(fy) for a in fy]

        
        x=x+fx
        y=y+fy



# Save the array back to the file
np.savetxt(keyword+'_'+color+'_x.csv', x)
np.savetxt(keyword+'_'+color+'_y.csv', y)









